'use strict';
let list = [
    {
        id: 1,
        username: '明明很伤心',
        avatar: '我就是头像',
        nickname: '用户1号'
    },
    {
        id: 2,
        username: '明明很伤心',
        avatar: '我就是头像',
        nickname: '用户1号'
    },
    {
        id: 3,
        username: '明明很伤心',
        avatar: '我就是头像',
        nickname: '用户1号'
    },
    {
        id: 4,
        username: '明明很伤心',
        avatar: '我就是头像',
        nickname: '用户1号'
    },
]

async function fn_getAllItems(ctx, next) {
    ctx.body = list;
}
async function fn_getItemById(ctx, next) {
    let id = ctx.request.params.id || 0;
    let items = list.filter(item => {
        return item.id == id;
    });
    return items.length > 0 ? items[0] : {}
}
async function fn_addItem(ctx, next) {

}
async function fn_updateItem(ctx, next) {

}
async function fn_delItem(ctx, next) {

}

let obj = {
    'get /roles': fn_getAllItems,
    'get /roles/:id': fn_getItemById,
    'post /roles': fn_addItem,
    'put /roles/:id': fn_updateItem,
    'delete /roles/:id': fn_delItem,
}

module.exports = obj;